<?php
/*
	本插件：$this->model('model')->方法名();
	其他地方调用：model('jy_51job/model')->方法名();
*/
namespace jy_51job;
defined('BY_JYA') or exit('error');
class member extends \plugin{
	public function checkmember(){
		if(!$_SESSION['uid']){
			return 0;
		}
		$member=pdo_get('jy_51job_member',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),array('id','isshiming'));
		$memberid=$member['id'];
		if(!$memberid){
			$member=pdo_get('core_members',array('id'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
			$insert=array(
				'uniacid'=>$_SESSION['uniacid'],
				'mid'=>$_SESSION['uid'],
				'nickname'=>$member['nickname'],
				'usename'=>$member['username'],
				'mobile'=>$member['mobile'],
				'avatar'=>$member['avatar'],
				'sex'=>$member['sex'],
				'openid'=>$member['openid'],
				'createtime'=>TIMESTAMP,
			);
			pdo_insert('jy_51job_member',$insert);
			$memberid=pdo_insertid();
		}
		return $memberid;
	}
	public function checkinfo(){
		if(!$_SESSION['uid']){
			return 0;
		}
		$member=pdo_get('jy_51job_member',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
		$memberid=$member['id'];
		if(!$memberid){
			return 0;
		}
		if(!$member['mobile'] || !$member['nickname'] || !$member['sex'] || !$member['birth']){
			exi('请先完善个人信息！','','jy_51job/myset/');
		}
		return '';
	}
	public function checkshiming(){
		if(!$_SESSION['uid']){
			return 0;
		}
		$member=pdo_get('jy_51job_member',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),array('id','isshiming'));
		$memberid=$member['id'];
		if(!$memberid){
			return 0;
		}
		if(!$member['isshiming']){
			$basic=$this->plugin_setting('basic');
			if($basic['isshiming'] && !$member['isshiming']){
				exi('请先实名认证','','jy_faceid/index/');
			}
		}
		return $memberid;
	}
	public function member_show($id,$default_url='',$default=false,$mid=0){
		if($mid){
			$member=pdo_get('jy_51job_member',array('mid'=>intval($mid)),array('id','mid','nickname','usename','avatar','mobile','sex'));
		}else{
			$member=pdo_get('jy_51job_member',array('id'=>intval($id)),array('id','mid','nickname','usename','avatar','mobile','sex'));
		}
		if(!$member['mobile']){
			$member['mobile']=pdo_getcolumn('core_members',array('id'=>$member['mid'],'uniacid'=>$_SESSION['uniacid']),'mobile');
			if($member['mobile']){
				pdo_update('jy_51job_member',array('mobile'=>$member['mobile']),array('mid'=>$member['mid'],'uniacid'=>$_SESSION['uniacid']));
			}
		}
		if(!$member){
			$member=$default?:array('nickname'=>'无');
		}else{
			$member['nickname']=$member['usename']?:$member['nickname'];
			$member['nickname']=$member['nickname']?:'无';
			$member['avatar']=tomedia($member['avatar']);
		}
		$member['url']='jy_51job/member/look/';
		return $member;
	}
}
?>